<?php

namespace core;

use \core\view\view;
use \core\lib\email;
use \core\lib\logs;
use \core\lib\router;
use \core\lib\session;
use \core\lib\verify;

class mvc
{
	static public $classMap = array();
	/*
		load函数功能:
			自动加载类库
	*/
	static public function load($class)
	{
		if(isset(self::$classMap[$class])){
			return true;
		}
		else{
			$class = str_replace('\\', '/', $class);
			$file = MVC . '/' . $class . '.class.php';
			if(is_file($file)){
				include_once($file);
				self::$classMap[$class] = true;
				return true;
			}
			else{
				logs::write("Error 404 - The Class '{$class}' not load!", "chrome");
				view::display('error/404.html');
				return false;
			}
		}
	}
	
	/*
		run函数功能:
			启动框架
	*/
	static public function run()
	{
		logs::init();
		session::start();
		$router = new router();
		
		$controller = $router->controller;
		$method = $router->method;
		
		$controllerName = '\\' . MODULE . '\\controller\\' . $controller . 'Controller';
		$controllerClass = new $controllerName();
		
		$controllerClass->$method();
	}
}